﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace E2
{
    public partial class Form1 : Form
    {
        FileStream file1, file2;
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "D:\\";//注意这里写路径时要用c:\\而不是c:\
            openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            string fName;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fName = openFileDialog.FileName;
                file2 = new FileStream(fName, FileMode.Open, FileAccess.Read);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = "D:\\";//注意这里写路径时要用c:\\而不是c:\
            openFileDialog.Filter = "文本文件|*.*|C#文件|*.cs|所有文件|*.*";
            openFileDialog.RestoreDirectory = true;
            openFileDialog.FilterIndex = 1;
            string fName;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                fName = openFileDialog.FileName;
                file1 = new FileStream(fName,FileMode.Open,FileAccess.Read);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            
            if (file1 == null || file2 == null) { return; }
            FileStream file = new FileStream("data\\test.txt", FileMode.OpenOrCreate, FileAccess.Write);
            using (StreamWriter writer=new StreamWriter(file, Encoding.Default))
            {
                using(StreamReader reader1=new StreamReader(file1, Encoding.Default))
                {
                    using(StreamReader reader2=new StreamReader(file2, Encoding.Default))
                    {
                        writer.Write(reader1.ReadToEnd()+ reader2.ReadToEnd());

                    }
                }
            }
        }
    }
}
